{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Imports\n",
    "\n",
    "Import all the modules and functionalities we need."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "# Import standard libraries.\n",
    "import os\n",
    "\n",
    "# Import third party libraries.\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "\n",
    "# Import custom libraries/scripts.\n",
    "import annotations\n",
    "import helpers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Loading data\n",
    "\n",
    "Fetch all our relevant data for the current analysis."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set working contants.\n",
    "EXPERIMENTS_PATH = r'\\\\10.40.12.80\\home\\PhD\\Results\\Competition\\DL\\Four-Arena Setup\\WT_mating_status\\processed'\n",
    "FPS = 60\n",
    "N_MINUTES = 60\n",
    "N_FRAMES = N_MINUTES * 60 * FPS\n",
    "INK = 'black'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set figure configurations.\n",
    "sns.set(\n",
    "        context='paper',\n",
    "        style='ticks',\n",
    "        font='sans-serif',\n",
    "        font_scale=1.0, \n",
    "        rc={\n",
    "            'axes.axisbelow': True,\n",
    "            'axes.edgecolor': INK,\n",
    "            'axes.facecolor': 'white' if INK=='black' else 'black',\n",
    "            'axes.grid': False,\n",
    "            'axes.labelcolor': INK,\n",
    "            'axes.labelsize': 13.0,\n",
    "            'axes.labelweight': 'normal',\n",
    "            'axes.linewidth': 1.0,\n",
    "            'axes.spines.left': True,\n",
    "            'axes.spines.bottom': True,\n",
    "            'axes.spines.top': False,\n",
    "            'axes.spines.right': False,\n",
    "            'axes.titlepad': 15.0,\n",
    "            'axes.titlesize': 20.0,\n",
    "            'axes.titleweight': 'bold',\n",
    "            'figure.facecolor': 'white' if INK=='black' else 'black',\n",
    "            'figure.figsize': [6.0, 4.0],\n",
    "            'figure.titlesize': 30.0,\n",
    "            'figure.titleweight': 'bold',\n",
    "            'font.family': ['sans-serif'],\n",
    "            'font.sans-serif': ['Arial'],\n",
    "            'legend.frameon': False,\n",
    "            'legend.fontsize': 11.0,\n",
    "            'lines.color': INK,\n",
    "            'lines.linewidth': 1.0,\n",
    "            'patch.edgecolor': INK,\n",
    "            'savefig.dpi': 300,\n",
    "            'savefig.format': 'png',\n",
    "            'savefig.bbox': 'tight',\n",
    "            'savefig.transparent': True,\n",
    "            'text.color': INK,\n",
    "            'text.usetex': False,\n",
    "            'xtick.color': INK,\n",
    "            'xtick.direction': 'out',\n",
    "            'xtick.labelsize': 12.0,\n",
    "            'xtick.major.pad': 5.0,\n",
    "            'xtick.major.size': 0.0,\n",
    "            'xtick.major.width': 1.0,\n",
    "            'xtick.minor.size': 0.0,\n",
    "            'xtick.minor.width': 0.4,\n",
    "            'ytick.color': INK,\n",
    "            'ytick.direction': 'out',\n",
    "            'ytick.labelsize': 12.0,\n",
    "            'ytick.major.pad': 5.0,\n",
    "            'ytick.major.size': 3.0,\n",
    "            'ytick.major.width': 1.0,\n",
    "            'ytick.minor.size': 0.0,\n",
    "            'ytick.minor.width': 0.4\n",
    "           }\n",
    "       )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Folder already exists, skipping.\n"
     ]
    }
   ],
   "source": [
    "# Prepare the Figures folder to save our graphs in.\n",
    "savepath = os.path.join(r'C:\\Users\\Miguel\\Desktop\\paper_data', 'paper_figures', 'figure1')\n",
    "try:\n",
    "    os.makedirs(savepath)\n",
    "    print('New folder created.')\n",
    "except FileExistsError:\n",
    "    print('Folder already exists, skipping.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Paths to conditions:\n",
      " ['\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin']\n"
     ]
    }
   ],
   "source": [
    "# Set the conditions to analyze.\n",
    "condition_order = ['virgin_virgin']\n",
    "conditions = [item.path for item in os.scandir(EXPERIMENTS_PATH) if item.name in condition_order]\n",
    "print('Paths to conditions:\\n', conditions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['video_2017-09-05T15_42_04_arena3', 'video_2017-09-07T13_28_02_arena4']\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "# Create a list of all the experiments that we DO NOT want to analyze.\n",
    "intruders = []\n",
    "for condition_path in conditions:\n",
    "    condition = os.path.basename(condition_path)\n",
    "    for file in os.listdir(condition_path):\n",
    "        if 'quality_control' in file:\n",
    "\n",
    "            # Read the quality.csv file to check which experiments are usable for analysis.\n",
    "            quality_file = os.path.join(condition_path, file)\n",
    "            quality_df = pd.read_csv(quality_file, usecols=[0,1], index_col=0)\n",
    "            quality_df = quality_df[quality_df['is_usable'] == False].index.values\n",
    "\n",
    "            for value in quality_df:\n",
    "                intruders.append(value + '_slice1' if condition=='virgin_added' else value)\n",
    "\n",
    "print(intruders)             \n",
    "print(len(intruders))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\n",
      " virgin_virgin\n",
      "Copulation too short: video_2017-09-06T13_42_13_arena3\n",
      "Copulation too short: video_2017-09-26T14_52_18_arena3\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'virgin_virgin': ['\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-05T13_28_41_arena4',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-05T14_34_55_arena2',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-06T13_42_13_arena1',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-06T14_45_32_arena3',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-07T14_37_38_arena3',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-07T14_37_38_arena4',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-08T13_26_13_arena3',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-12T13_30_06_arena4',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-12T14_36_55_arena3',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-12T16_18_15_arena4',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-13T14_34_18_arena2',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-20T13_43_53_arena3',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-20T14_48_55_arena2',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-21T13_38_55_arena4',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-21T15_57_23_arena2',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-26T13_40_19_arena1',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-28T13_36_06_arena4',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-28T14_44_01_arena3',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-09-28T15_55_49_arena3',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-10-12T15_50_43_arena2',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-10-13T16_06_33_arena2',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-10-18T15_19_17_arena3',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-10-19T13_50_56_arena2',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-10-20T13_21_06_arena2',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-10-20T15_44_09_arena2',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-10-24T16_13_35_arena4',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-10-25T14_55_12_arena1',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-11-02T13_37_48_arena3',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-11-02T14_48_28_arena4',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-11-02T16_11_06_arena3',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-11-03T14_54_45_arena1',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-11-03T16_20_50_arena4',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-12-20T12_58_51_arena4',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\Four-Arena Setup\\\\WT_mating_status\\\\processed\\\\virgin_virgin\\\\video_2017-12-20T14_01_01_arena3']}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Load all usable experiments for each condition.\n",
    "experiments = {condition: [] for condition in condition_order}\n",
    "\n",
    "for condition_path in conditions:\n",
    "    \n",
    "    condition = os.path.basename(condition_path)\n",
    "    print('\\t\\n', condition)\n",
    "    \n",
    "    for item in os.scandir(condition_path):\n",
    "        if item.is_dir() and item.name not in intruders:\n",
    "            \n",
    "            annotation_video = annotations.read(item.path.split('_slice')[0] + '.csv')\n",
    "            \n",
    "            try:\n",
    "                copulation = annotation_video[0].events[0]\n",
    "\n",
    "                # Filter out videos where copulation is interrupted.\n",
    "                copulation_end = copulation.time_interval[1]\n",
    "                if copulation_end==N_FRAMES:\n",
    "                    print('Copulation interrupted:', item.name)\n",
    "                    continue\n",
    "\n",
    "                # Filter out videos where copulation lasts less than 8 minutes.\n",
    "                copulation_duration = copulation.duration\n",
    "                if copulation_duration <= 8 * 60 * FPS:\n",
    "                    print('Copulation too short:', item.name)\n",
    "                    continue\n",
    "            \n",
    "            except IndexError as error:\n",
    "                continue\n",
    "\n",
    "            experiments[condition].append(item.path.split('_slice')[0])\n",
    "\n",
    "experiments"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Aggression Analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Iteration: 0 \n",
      "Experiment: video_2017-09-05T13_28_41_arena4 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 1 \n",
      "Experiment: video_2017-09-05T14_34_55_arena2 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 2 \n",
      "Experiment: video_2017-09-06T13_42_13_arena1 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 3 \n",
      "Experiment: video_2017-09-06T14_45_32_arena3 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 4 \n",
      "Experiment: video_2017-09-07T14_37_38_arena3 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 5 \n",
      "Experiment: video_2017-09-07T14_37_38_arena4 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 6 \n",
      "Experiment: video_2017-09-08T13_26_13_arena3 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 7 \n",
      "Experiment: video_2017-09-12T13_30_06_arena4 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 8 \n",
      "Experiment: video_2017-09-12T14_36_55_arena3 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "No aggression for experiment video_2017-09-12T14_36_55_arena3\n",
      "Iteration: 9 \n",
      "Experiment: video_2017-09-12T16_18_15_arena4 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 10 \n",
      "Experiment: video_2017-09-13T14_34_18_arena2 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 11 \n",
      "Experiment: video_2017-09-20T13_43_53_arena3 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "No aggression for experiment video_2017-09-20T13_43_53_arena3\n",
      "Iteration: 12 \n",
      "Experiment: video_2017-09-20T14_48_55_arena2 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 13 \n",
      "Experiment: video_2017-09-21T13_38_55_arena4 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 14 \n",
      "Experiment: video_2017-09-21T15_57_23_arena2 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 15 \n",
      "Experiment: video_2017-09-26T13_40_19_arena1 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 16 \n",
      "Experiment: video_2017-09-28T13_36_06_arena4 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "No aggression for experiment video_2017-09-28T13_36_06_arena4\n",
      "Iteration: 17 \n",
      "Experiment: video_2017-09-28T14_44_01_arena3 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 18 \n",
      "Experiment: video_2017-09-28T15_55_49_arena3 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "No aggression for experiment video_2017-09-28T15_55_49_arena3\n",
      "Iteration: 19 \n",
      "Experiment: video_2017-10-12T15_50_43_arena2 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "No aggression for experiment video_2017-10-12T15_50_43_arena2\n",
      "Iteration: 20 \n",
      "Experiment: video_2017-10-13T16_06_33_arena2 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "No aggression for experiment video_2017-10-13T16_06_33_arena2\n",
      "Iteration: 21 \n",
      "Experiment: video_2017-10-18T15_19_17_arena3 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 22 \n",
      "Experiment: video_2017-10-19T13_50_56_arena2 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "No aggression for experiment video_2017-10-19T13_50_56_arena2\n",
      "Iteration: 23 \n",
      "Experiment: video_2017-10-20T13_21_06_arena2 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 24 \n",
      "Experiment: video_2017-10-20T15_44_09_arena2 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 25 \n",
      "Experiment: video_2017-10-24T16_13_35_arena4 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 26 \n",
      "Experiment: video_2017-10-25T14_55_12_arena1 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 27 \n",
      "Experiment: video_2017-11-02T13_37_48_arena3 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 28 \n",
      "Experiment: video_2017-11-02T14_48_28_arena4 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 29 \n",
      "Experiment: video_2017-11-02T16_11_06_arena3 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 30 \n",
      "Experiment: video_2017-11-03T14_54_45_arena1 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "No aggression for experiment video_2017-11-03T14_54_45_arena1\n",
      "Iteration: 31 \n",
      "Experiment: video_2017-11-03T16_20_50_arena4 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 32 \n",
      "Experiment: video_2017-12-20T12_58_51_arena4 \n",
      "Condition: virgin_virgin \n",
      "\n",
      "Iteration: 33 \n",
      "Experiment: video_2017-12-20T14_01_01_arena3 \n",
      "Condition: virgin_virgin \n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>has_aggression</th>\n",
       "      <th>latency</th>\n",
       "      <th>latency_mins</th>\n",
       "      <th>nframes</th>\n",
       "      <th>nbouts</th>\n",
       "      <th>ratio_frames</th>\n",
       "      <th>ratio_bouts</th>\n",
       "      <th>condition</th>\n",
       "      <th>experiment</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>True</td>\n",
       "      <td>31444.0</td>\n",
       "      <td>8.734444</td>\n",
       "      <td>180</td>\n",
       "      <td>1</td>\n",
       "      <td>0.004277</td>\n",
       "      <td>0.085545</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-05T13_28_41_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>True</td>\n",
       "      <td>853.0</td>\n",
       "      <td>0.236944</td>\n",
       "      <td>617</td>\n",
       "      <td>10</td>\n",
       "      <td>0.011225</td>\n",
       "      <td>0.654950</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-05T14_34_55_arena2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>True</td>\n",
       "      <td>11456.0</td>\n",
       "      <td>3.182222</td>\n",
       "      <td>343</td>\n",
       "      <td>6</td>\n",
       "      <td>0.009081</td>\n",
       "      <td>0.571867</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-06T13_42_13_arena1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>True</td>\n",
       "      <td>3703.0</td>\n",
       "      <td>1.028611</td>\n",
       "      <td>950</td>\n",
       "      <td>13</td>\n",
       "      <td>0.018440</td>\n",
       "      <td>0.908403</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-06T14_45_32_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>True</td>\n",
       "      <td>12260.0</td>\n",
       "      <td>3.405556</td>\n",
       "      <td>579</td>\n",
       "      <td>7</td>\n",
       "      <td>0.012334</td>\n",
       "      <td>0.536798</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-07T14_37_38_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>True</td>\n",
       "      <td>7429.0</td>\n",
       "      <td>2.063611</td>\n",
       "      <td>53</td>\n",
       "      <td>5</td>\n",
       "      <td>0.001017</td>\n",
       "      <td>0.345403</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-07T14_37_38_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>True</td>\n",
       "      <td>8016.0</td>\n",
       "      <td>2.226667</td>\n",
       "      <td>684</td>\n",
       "      <td>12</td>\n",
       "      <td>0.013323</td>\n",
       "      <td>0.841433</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-08T13_26_13_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>True</td>\n",
       "      <td>18037.0</td>\n",
       "      <td>5.010278</td>\n",
       "      <td>734</td>\n",
       "      <td>5</td>\n",
       "      <td>0.014170</td>\n",
       "      <td>0.347490</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-12T13_30_06_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-12T14_36_55_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>True</td>\n",
       "      <td>7848.0</td>\n",
       "      <td>2.180000</td>\n",
       "      <td>94</td>\n",
       "      <td>3</td>\n",
       "      <td>0.001893</td>\n",
       "      <td>0.217461</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-12T16_18_15_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>True</td>\n",
       "      <td>8802.0</td>\n",
       "      <td>2.445000</td>\n",
       "      <td>478</td>\n",
       "      <td>4</td>\n",
       "      <td>0.008266</td>\n",
       "      <td>0.249023</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-13T14_34_18_arena2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-20T13_43_53_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>True</td>\n",
       "      <td>21432.0</td>\n",
       "      <td>5.953333</td>\n",
       "      <td>29</td>\n",
       "      <td>2</td>\n",
       "      <td>0.000928</td>\n",
       "      <td>0.230496</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-20T14_48_55_arena2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>True</td>\n",
       "      <td>11140.0</td>\n",
       "      <td>3.094444</td>\n",
       "      <td>248</td>\n",
       "      <td>3</td>\n",
       "      <td>0.003984</td>\n",
       "      <td>0.173516</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-21T13_38_55_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>True</td>\n",
       "      <td>7358.0</td>\n",
       "      <td>2.043889</td>\n",
       "      <td>998</td>\n",
       "      <td>19</td>\n",
       "      <td>0.020252</td>\n",
       "      <td>1.388015</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-21T15_57_23_arena2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>True</td>\n",
       "      <td>24055.0</td>\n",
       "      <td>6.681944</td>\n",
       "      <td>80</td>\n",
       "      <td>3</td>\n",
       "      <td>0.001516</td>\n",
       "      <td>0.204693</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-26T13_40_19_arena1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-28T13_36_06_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>True</td>\n",
       "      <td>6061.0</td>\n",
       "      <td>1.683611</td>\n",
       "      <td>328</td>\n",
       "      <td>3</td>\n",
       "      <td>0.006668</td>\n",
       "      <td>0.219557</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-28T14_44_01_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-09-28T15_55_49_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-10-12T15_50_43_arena2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-10-13T16_06_33_arena2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>True</td>\n",
       "      <td>46715.0</td>\n",
       "      <td>12.976389</td>\n",
       "      <td>313</td>\n",
       "      <td>3</td>\n",
       "      <td>0.005885</td>\n",
       "      <td>0.203065</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-10-18T15_19_17_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-10-19T13_50_56_arena2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>True</td>\n",
       "      <td>8565.0</td>\n",
       "      <td>2.379167</td>\n",
       "      <td>199</td>\n",
       "      <td>6</td>\n",
       "      <td>0.003502</td>\n",
       "      <td>0.380134</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-10-20T13_21_06_arena2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>True</td>\n",
       "      <td>22481.0</td>\n",
       "      <td>6.244722</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000093</td>\n",
       "      <td>0.067064</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-10-20T15_44_09_arena2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>True</td>\n",
       "      <td>10145.0</td>\n",
       "      <td>2.818056</td>\n",
       "      <td>127</td>\n",
       "      <td>2</td>\n",
       "      <td>0.002336</td>\n",
       "      <td>0.132448</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-10-24T16_13_35_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>True</td>\n",
       "      <td>18406.0</td>\n",
       "      <td>5.112778</td>\n",
       "      <td>511</td>\n",
       "      <td>9</td>\n",
       "      <td>0.009165</td>\n",
       "      <td>0.581103</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-10-25T14_55_12_arena1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>True</td>\n",
       "      <td>22757.0</td>\n",
       "      <td>6.321389</td>\n",
       "      <td>504</td>\n",
       "      <td>8</td>\n",
       "      <td>0.009492</td>\n",
       "      <td>0.542424</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-11-02T13_37_48_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>True</td>\n",
       "      <td>17448.0</td>\n",
       "      <td>4.846667</td>\n",
       "      <td>338</td>\n",
       "      <td>2</td>\n",
       "      <td>0.006726</td>\n",
       "      <td>0.143281</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-11-02T14_48_28_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>True</td>\n",
       "      <td>32337.0</td>\n",
       "      <td>8.982500</td>\n",
       "      <td>122</td>\n",
       "      <td>1</td>\n",
       "      <td>0.002682</td>\n",
       "      <td>0.079138</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-11-02T16_11_06_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-11-03T14_54_45_arena1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>True</td>\n",
       "      <td>55427.0</td>\n",
       "      <td>15.396389</td>\n",
       "      <td>71</td>\n",
       "      <td>1</td>\n",
       "      <td>0.001172</td>\n",
       "      <td>0.059423</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-11-03T16_20_50_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>True</td>\n",
       "      <td>14378.0</td>\n",
       "      <td>3.993889</td>\n",
       "      <td>171</td>\n",
       "      <td>2</td>\n",
       "      <td>0.004402</td>\n",
       "      <td>0.185328</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-12-20T12_58_51_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>True</td>\n",
       "      <td>10803.0</td>\n",
       "      <td>3.000833</td>\n",
       "      <td>151</td>\n",
       "      <td>3</td>\n",
       "      <td>0.004024</td>\n",
       "      <td>0.287777</td>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>video_2017-12-20T14_01_01_arena3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    has_aggression  latency  latency_mins  nframes  nbouts  ratio_frames  \\\n",
       "0             True  31444.0      8.734444      180       1      0.004277   \n",
       "1             True    853.0      0.236944      617      10      0.011225   \n",
       "2             True  11456.0      3.182222      343       6      0.009081   \n",
       "3             True   3703.0      1.028611      950      13      0.018440   \n",
       "4             True  12260.0      3.405556      579       7      0.012334   \n",
       "5             True   7429.0      2.063611       53       5      0.001017   \n",
       "6             True   8016.0      2.226667      684      12      0.013323   \n",
       "7             True  18037.0      5.010278      734       5      0.014170   \n",
       "8            False      NaN      0.000000        0       0      0.000000   \n",
       "9             True   7848.0      2.180000       94       3      0.001893   \n",
       "10            True   8802.0      2.445000      478       4      0.008266   \n",
       "11           False      NaN      0.000000        0       0      0.000000   \n",
       "12            True  21432.0      5.953333       29       2      0.000928   \n",
       "13            True  11140.0      3.094444      248       3      0.003984   \n",
       "14            True   7358.0      2.043889      998      19      0.020252   \n",
       "15            True  24055.0      6.681944       80       3      0.001516   \n",
       "16           False      NaN      0.000000        0       0      0.000000   \n",
       "17            True   6061.0      1.683611      328       3      0.006668   \n",
       "18           False      NaN      0.000000        0       0      0.000000   \n",
       "19           False      NaN      0.000000        0       0      0.000000   \n",
       "20           False      NaN      0.000000        0       0      0.000000   \n",
       "21            True  46715.0     12.976389      313       3      0.005885   \n",
       "22           False      NaN      0.000000        0       0      0.000000   \n",
       "23            True   8565.0      2.379167      199       6      0.003502   \n",
       "24            True  22481.0      6.244722        5       1      0.000093   \n",
       "25            True  10145.0      2.818056      127       2      0.002336   \n",
       "26            True  18406.0      5.112778      511       9      0.009165   \n",
       "27            True  22757.0      6.321389      504       8      0.009492   \n",
       "28            True  17448.0      4.846667      338       2      0.006726   \n",
       "29            True  32337.0      8.982500      122       1      0.002682   \n",
       "30           False      NaN      0.000000        0       0      0.000000   \n",
       "31            True  55427.0     15.396389       71       1      0.001172   \n",
       "32            True  14378.0      3.993889      171       2      0.004402   \n",
       "33            True  10803.0      3.000833      151       3      0.004024   \n",
       "\n",
       "    ratio_bouts      condition                        experiment  \n",
       "0      0.085545  virgin_virgin  video_2017-09-05T13_28_41_arena4  \n",
       "1      0.654950  virgin_virgin  video_2017-09-05T14_34_55_arena2  \n",
       "2      0.571867  virgin_virgin  video_2017-09-06T13_42_13_arena1  \n",
       "3      0.908403  virgin_virgin  video_2017-09-06T14_45_32_arena3  \n",
       "4      0.536798  virgin_virgin  video_2017-09-07T14_37_38_arena3  \n",
       "5      0.345403  virgin_virgin  video_2017-09-07T14_37_38_arena4  \n",
       "6      0.841433  virgin_virgin  video_2017-09-08T13_26_13_arena3  \n",
       "7      0.347490  virgin_virgin  video_2017-09-12T13_30_06_arena4  \n",
       "8      0.000000  virgin_virgin  video_2017-09-12T14_36_55_arena3  \n",
       "9      0.217461  virgin_virgin  video_2017-09-12T16_18_15_arena4  \n",
       "10     0.249023  virgin_virgin  video_2017-09-13T14_34_18_arena2  \n",
       "11     0.000000  virgin_virgin  video_2017-09-20T13_43_53_arena3  \n",
       "12     0.230496  virgin_virgin  video_2017-09-20T14_48_55_arena2  \n",
       "13     0.173516  virgin_virgin  video_2017-09-21T13_38_55_arena4  \n",
       "14     1.388015  virgin_virgin  video_2017-09-21T15_57_23_arena2  \n",
       "15     0.204693  virgin_virgin  video_2017-09-26T13_40_19_arena1  \n",
       "16     0.000000  virgin_virgin  video_2017-09-28T13_36_06_arena4  \n",
       "17     0.219557  virgin_virgin  video_2017-09-28T14_44_01_arena3  \n",
       "18     0.000000  virgin_virgin  video_2017-09-28T15_55_49_arena3  \n",
       "19     0.000000  virgin_virgin  video_2017-10-12T15_50_43_arena2  \n",
       "20     0.000000  virgin_virgin  video_2017-10-13T16_06_33_arena2  \n",
       "21     0.203065  virgin_virgin  video_2017-10-18T15_19_17_arena3  \n",
       "22     0.000000  virgin_virgin  video_2017-10-19T13_50_56_arena2  \n",
       "23     0.380134  virgin_virgin  video_2017-10-20T13_21_06_arena2  \n",
       "24     0.067064  virgin_virgin  video_2017-10-20T15_44_09_arena2  \n",
       "25     0.132448  virgin_virgin  video_2017-10-24T16_13_35_arena4  \n",
       "26     0.581103  virgin_virgin  video_2017-10-25T14_55_12_arena1  \n",
       "27     0.542424  virgin_virgin  video_2017-11-02T13_37_48_arena3  \n",
       "28     0.143281  virgin_virgin  video_2017-11-02T14_48_28_arena4  \n",
       "29     0.079138  virgin_virgin  video_2017-11-02T16_11_06_arena3  \n",
       "30     0.000000  virgin_virgin  video_2017-11-03T14_54_45_arena1  \n",
       "31     0.059423  virgin_virgin  video_2017-11-03T16_20_50_arena4  \n",
       "32     0.185328  virgin_virgin  video_2017-12-20T12_58_51_arena4  \n",
       "33     0.287777  virgin_virgin  video_2017-12-20T14_01_01_arena3  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aggression_df = pd.DataFrame()\n",
    "\n",
    "for condition in condition_order:\n",
    "    for h, experiment_path in enumerate(experiments[condition]):\n",
    "\n",
    "        experiment = os.path.basename(experiment_path)\n",
    "        \n",
    "        print('Iteration:', h, '\\nExperiment:', experiment, '\\nCondition:', condition, '\\n')\n",
    "        \n",
    "        # Read .csv annotation files.\n",
    "        annotation_video = annotations.read(experiment_path + '.csv')\n",
    "        copulation = annotation_video[0].events[0]\n",
    "        aggression_events = annotation_video[1].events\n",
    "        n_events = len(aggression_events)\n",
    "\n",
    "        # In case there is aggression, do the necessary calculations.\n",
    "        if n_events > 0:\n",
    "\n",
    "            latency =  aggression_events[0].time - copulation.time\n",
    "            latency_mins = latency / (60 * FPS)\n",
    "            ratio_frames = sum([aggression.duration for aggression in aggression_events]) / copulation.duration\n",
    "            ratio_bouts = n_events / (copulation.duration / (60 * FPS))\n",
    "            \n",
    "            aggression_data = pd.DataFrame({'has_aggression': True,\n",
    "                                            'latency': latency,\n",
    "                                            'latency_mins': latency_mins,\n",
    "                                            'nframes': sum([aggression.duration for aggression in aggression_events]),\n",
    "                                            'nbouts': n_events,\n",
    "                                            'ratio_frames': ratio_frames,\n",
    "                                            'ratio_bouts': ratio_bouts,\n",
    "                                            'condition': condition,\n",
    "                                            'experiment': experiment},\n",
    "                                            index=[h],\n",
    "                                           )\n",
    "\n",
    "        # If not, preset our dictionary with default values.\n",
    "        else:\n",
    "            print('No aggression for experiment', experiment)\n",
    "            \n",
    "            aggression_data = pd.DataFrame({'has_aggression': False,\n",
    "                                            'latency': np.nan,\n",
    "                                            'latency_mins': 0,\n",
    "                                            'nframes': 0,\n",
    "                                            'nbouts': 0,\n",
    "                                            'ratio_frames': 0, \n",
    "                                            'ratio_bouts': 0,\n",
    "                                            'condition': condition,\n",
    "                                            'experiment': experiment},\n",
    "                                            index=[h],\n",
    "                                           )\n",
    "\n",
    "        # Concatenate all data together.\n",
    "        aggression_df = pd.concat([aggression_df, aggression_data], ignore_index=True)\n",
    "\n",
    "aggression_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>n_aggression</th>\n",
       "      <th>n_experiments</th>\n",
       "      <th>aggression_rate</th>\n",
       "      <th>condition</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>26</td>\n",
       "      <td>34</td>\n",
       "      <td>0.764706</td>\n",
       "      <td>virgin_virgin</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   n_aggression  n_experiments  aggression_rate      condition\n",
       "0            26             34         0.764706  virgin_virgin"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Re-arrange original aggression DataFrame to get aggression rate.\n",
    "aggression_rate_df = pd.DataFrame()\n",
    "has_aggression_list = []\n",
    "for condition in condition_order:\n",
    "    \n",
    "    aggression_column = aggression_df[aggression_df['condition']==condition]\n",
    "    n_exp = aggression_column.shape[0]\n",
    "    \n",
    "    has_aggression = aggression_column[aggression_column['has_aggression']==True]\n",
    "    n_aggression = has_aggression.shape[0]\n",
    "    has_aggression_list.append(n_aggression)\n",
    "    aggression_rate = n_aggression / n_exp\n",
    "    rate_data = pd.DataFrame({'n_aggression': n_aggression,\n",
    "                              'n_experiments': n_exp,\n",
    "                              'aggression_rate': aggression_rate,\n",
    "                              'condition': condition,\n",
    "                             }, index=[0])\n",
    "        \n",
    "    aggression_rate_df = pd.concat([aggression_rate_df, rate_data], ignore_index=True)\n",
    "\n",
    "aggression_rate_df = aggression_rate_df[['n_aggression', 'n_experiments', 'aggression_rate', 'condition']]\n",
    "aggression_rate_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## How many frames of aggression do we observe?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>condition</th>\n",
       "      <th>ratio_frames</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.004277</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.011225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.009081</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.018440</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.012334</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.001017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.013323</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.014170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.001893</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.008266</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000928</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.003984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.020252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.001516</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.006668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.005885</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.003502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000093</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.002336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.009165</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.009492</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.006726</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.002682</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.001172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.004402</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.004024</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        condition  ratio_frames\n",
       "0   virgin_virgin      0.004277\n",
       "1   virgin_virgin      0.011225\n",
       "2   virgin_virgin      0.009081\n",
       "3   virgin_virgin      0.018440\n",
       "4   virgin_virgin      0.012334\n",
       "5   virgin_virgin      0.001017\n",
       "6   virgin_virgin      0.013323\n",
       "7   virgin_virgin      0.014170\n",
       "8   virgin_virgin      0.000000\n",
       "9   virgin_virgin      0.001893\n",
       "10  virgin_virgin      0.008266\n",
       "11  virgin_virgin      0.000000\n",
       "12  virgin_virgin      0.000928\n",
       "13  virgin_virgin      0.003984\n",
       "14  virgin_virgin      0.020252\n",
       "15  virgin_virgin      0.001516\n",
       "16  virgin_virgin      0.000000\n",
       "17  virgin_virgin      0.006668\n",
       "18  virgin_virgin      0.000000\n",
       "19  virgin_virgin      0.000000\n",
       "20  virgin_virgin      0.000000\n",
       "21  virgin_virgin      0.005885\n",
       "22  virgin_virgin      0.000000\n",
       "23  virgin_virgin      0.003502\n",
       "24  virgin_virgin      0.000093\n",
       "25  virgin_virgin      0.002336\n",
       "26  virgin_virgin      0.009165\n",
       "27  virgin_virgin      0.009492\n",
       "28  virgin_virgin      0.006726\n",
       "29  virgin_virgin      0.002682\n",
       "30  virgin_virgin      0.000000\n",
       "31  virgin_virgin      0.001172\n",
       "32  virgin_virgin      0.004402\n",
       "33  virgin_virgin      0.004024"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ratio_frames_df = aggression_df.copy()\n",
    "ratio_frames_df = ratio_frames_df[['condition', 'ratio_frames']]\n",
    "ratio_frames_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAH0AAAEFCAYAAADOhug9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO2dd1hUV/7G3ykw9A6CVJEq1QLBFjRRo1Fj1oKsMYKJRrNhNVljy5qIputvk7ia6Lq6UdGAsURRjDHZ2IJBRRlBQFB6k6EzM8Aw5fz+YJ1IkJmLMHOvmft5nnkebpkz7+W959zT7vdwCCEELAYFl24BLPqHNd0AYU03QFjTDRDWdAOENd0A0YvpBw8eRFhYGMLDwzFmzBhkZmb2OGfVqlXw8PBAeHg4wsPDMX/+fH1IM0yIjrlz5w5xdnYm1dXVhBBC0tLSiLu7e4/zoqKiSHp6uq7lsBBCOITotnOmtLQUubm5mD59OgBAJBLBzc0NEokExsbGAACZTAZra2tMnToVRUVF8PPzw+effw4PDw9dSjNc9HmHqVQq8tJLL5E5c+Z0219cXEymTZtGcnJyiEqlIlu2bCHh4eFEpVI9Mp2NGzcSAOoPS9/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BIaGkoCAgLI9OnTSUNDA7l+/ToJCwvTeA6LbnjiAw2x9J0/fI8cS09Y0w0Q1nQDhDX9MXnvvfcwbNgwBAUF4bPPPut2bMeOHZgwYQI9wqhAd03ySeTChQtk7NixRC6Xk7a2NuLl5UXu3LlDCCEkNzeXuLq6kujoaHpFaoDWnH7hwgVMmTIFL774Ivz9/dVLfjzM1atX1asyPviMHz++lxT1Q3R0NM6fPw8+nw+RSASFQgFzc3PIZDIsW7YMmzdvplWfVui8486fP0/Mzc1JRUUFUSqVJCIigqSmptIpqU+89957xMzMjMTFxRGVSkXeeust8p///IecP3+ezemaCA4OhpubG7hcLgIDA9HY2H1CAxNz+gM2bdqEuro6VFRUYPfu3SgvL8fixYu1f5FmaJ8uZWJiov77UWPjTz31FO3Ldf+eO3fuoKOjA+Hh4TAzM8Ps2bNx9epV5ObmIjw8HBKJBPfv38f8+fMZuWYs7Tn9SaS4uBhLly6FTCZDZ2cnTp48iSlTpiA/Px9CoRB79uzBqFGjGGk4wICc/iTy/PPP49q1axg+fDh4PB7mzJmD2NhYumVRhu17N0DY4t0AYU03QFjTDRDWdAOENd0AYU03QFjTDRDWdAOENd0AYU03QFjTDRDWdAOENd0AYU03QFjTDZD/B1fvlloVWFpKAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 90x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Initialize figure.\n",
    "n_conditions = ratio_frames_df['condition'].nunique()\n",
    "figure, axis = plt.subplots(figsize=(1.25*n_conditions, 4))\n",
    "\n",
    "# Draw the boxplot.\n",
    "sns.boxplot(x='condition',\n",
    "            y='ratio_frames',\n",
    "            data=ratio_frames_df,\n",
    "            palette=['steelblue'],\n",
    "            width=0.6,\n",
    "            showfliers=False,\n",
    "            boxprops={'edgecolor': INK},\n",
    "            medianprops={'color': INK},\n",
    "            whiskerprops={'color': INK},\n",
    "            capprops={'color': INK}\n",
    "           )\n",
    "\n",
    "# Draw the swarmplot.\n",
    "sns.swarmplot(x='condition',\n",
    "              y='ratio_frames',\n",
    "              data=ratio_frames_df,\n",
    "              palette=['steelblue'],\n",
    "              linewidth=0.75,\n",
    "              edgecolor=INK\n",
    "             )\n",
    "\n",
    "# Figure and axes formatting.\n",
    "axis.set_xlabel('')\n",
    "axis.set_xticklabels([''])\n",
    "axis.set_ylabel('Aggression Rate (%)')\n",
    "axis.set_ylim(0, 0.025)\n",
    "axis.set_yticks(np.arange(0, 0.025+0.001, 0.005))\n",
    "axis.set_yticklabels([y*100 for y in axis.get_yticks()])\n",
    "\n",
    "# Table definition.\n",
    "row1 = [str(ratio_frames_df.query('condition==\"'+condition+'\"').shape[0]) for condition in ratio_frames_df['condition'].unique()]\n",
    "cell_text = np.array([row1])\n",
    "\n",
    "row_labels = ['n =']\n",
    "summary_table = axis.table(cellText= cell_text,\n",
    "                           cellLoc='center',\n",
    "                           rowLabels=row_labels,\n",
    "                           rowLoc='center',\n",
    "                           colLoc='center'\n",
    "                          )\n",
    "\n",
    "summary_table.auto_set_font_size(False)\n",
    "summary_table.set_fontsize(11)\n",
    "\n",
    "properties = summary_table.properties()\n",
    "table_cells = properties['children']\n",
    "for cell in table_cells:\n",
    "    cell.set_height(0.12)\n",
    "    cell.set_alpha(0)\n",
    "\n",
    "# Saving parameters.\n",
    "filename = 'aggression_rate'\n",
    "plt.savefig(os.path.join(savepath, filename))\n",
    "\n",
    "plt.show()\n",
    "plt.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## How many bouts of aggressive behavior do we observe (normalized)? "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>condition</th>\n",
       "      <th>ratio_bouts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.085545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.654950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.571867</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.908403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.536798</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.345403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.841433</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.347490</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.217461</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.249023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.230496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.173516</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>1.388015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.204693</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.219557</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.203065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.380134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.067064</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.132448</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.581103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.542424</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.143281</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.079138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.059423</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.185328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>virgin_virgin</td>\n",
       "      <td>0.287777</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        condition  ratio_bouts\n",
       "0   virgin_virgin     0.085545\n",
       "1   virgin_virgin     0.654950\n",
       "2   virgin_virgin     0.571867\n",
       "3   virgin_virgin     0.908403\n",
       "4   virgin_virgin     0.536798\n",
       "5   virgin_virgin     0.345403\n",
       "6   virgin_virgin     0.841433\n",
       "7   virgin_virgin     0.347490\n",
       "8   virgin_virgin     0.000000\n",
       "9   virgin_virgin     0.217461\n",
       "10  virgin_virgin     0.249023\n",
       "11  virgin_virgin     0.000000\n",
       "12  virgin_virgin     0.230496\n",
       "13  virgin_virgin     0.173516\n",
       "14  virgin_virgin     1.388015\n",
       "15  virgin_virgin     0.204693\n",
       "16  virgin_virgin     0.000000\n",
       "17  virgin_virgin     0.219557\n",
       "18  virgin_virgin     0.000000\n",
       "19  virgin_virgin     0.000000\n",
       "20  virgin_virgin     0.000000\n",
       "21  virgin_virgin     0.203065\n",
       "22  virgin_virgin     0.000000\n",
       "23  virgin_virgin     0.380134\n",
       "24  virgin_virgin     0.067064\n",
       "25  virgin_virgin     0.132448\n",
       "26  virgin_virgin     0.581103\n",
       "27  virgin_virgin     0.542424\n",
       "28  virgin_virgin     0.143281\n",
       "29  virgin_virgin     0.079138\n",
       "30  virgin_virgin     0.000000\n",
       "31  virgin_virgin     0.059423\n",
       "32  virgin_virgin     0.185328\n",
       "33  virgin_virgin     0.287777"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ratio_bouts_df = aggression_df.copy()\n",
    "ratio_bouts_df = ratio_bouts_df[['condition', 'ratio_bouts']]\n",
    "ratio_bouts_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAH0AAAEFCAYAAADOhug9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO2deVhTx/7G34RA2IUglB0EBNkRxSIWd0VRyxXXulTbuntrb2sr1rZKbf1xb7WLdattXXrViq2Cu1VvXUpFcaUsgqJsYZGwhE2WhGR+f3CN5gLhBDk5wZzP8+R5OHMW3pM38505M3NmOIQQAhadgsu0ABbNw5qug7Cm6yCs6ToIa7oOwpqug2jMdEII5s2bh02bNrW7f+XKlXB2dkZQUBCCgoIwY8YMTUnTOXia+CdZWVlYvnw5UlJS4O/v3+4xycnJiI+PR1hYmCYk6TQayenbtm3DggULMG3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1jOrrFCZ/cRcvXiQmJiZEKBQSmUxGQkJCyPHjx5mUpBZr164lxsbGZN68eUQul5N3332X7N69m1y8eJHN6arw8/ODo6MjuFwuvL2928xRp405/QmffvopysvLIRQK8f3336OwsBBvvPEG07I6hfFx788OIGyvb/zll19WmglDG8jOzkZTUxOCgoJgbGyM6OhopKSkIDMzE0FBQaivr8ejR48wY8YMHDp0iGm5bWA8p/dEcnNzsXDhQjQ3N0MikeDYsWMYO3YssrKykJqaih9//BEDBw7USsMBLcjpPZHIyEhcv34d/fv3h56eHqZMmYKZM2cyLYsybNu7DsKGdx2ENV0HYU3XQVjTdRDWdB2ENV0HYU3XQVjTdRDWdB2ENV0HYU3XQVjTdRDWdB2ENV0HYU3XQf4fW/wKEn6T994AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 90x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Initialize figure.\n",
    "n_conditions = ratio_bouts_df['condition'].nunique()\n",
    "figure, axis = plt.subplots(figsize=(1.25*n_conditions, 4))\n",
    "\n",
    "# Draw the boxplot.\n",
    "sns.boxplot(x='condition',\n",
    "            y='ratio_bouts',\n",
    "            data=ratio_bouts_df,\n",
    "            palette=['steelblue'],\n",
    "            width=0.6,\n",
    "            showfliers=False,\n",
    "            boxprops={'edgecolor': INK},\n",
    "            medianprops={'color': INK},\n",
    "            whiskerprops={'color': INK},\n",
    "            capprops={'color': INK}\n",
    "           )\n",
    "\n",
    "# Draw the swarmplot.\n",
    "sns.swarmplot(x='condition',\n",
    "              y='ratio_bouts',\n",
    "              data=ratio_bouts_df,\n",
    "              palette=['steelblue'],\n",
    "              linewidth=0.75,\n",
    "              edgecolor=INK\n",
    "             )\n",
    "\n",
    "# Figure and axes formatting.\n",
    "axis.set_xlabel('')\n",
    "axis.set_xticklabels([''])\n",
    "axis.set_ylabel('# Bouts / Minute of Copulation')\n",
    "axis.set_ylim(0, 1.5)\n",
    "axis.set_yticks(np.arange(0, 1.5+0.1, 0.5))\n",
    "axis.set_yticklabels(np.arange(0, 1.5+0.1, 0.5))\n",
    "\n",
    "# Table definition.\n",
    "row1 = [str(ratio_bouts_df.query('condition==\"'+condition+'\"').shape[0]) for condition in ratio_bouts_df['condition'].unique()]\n",
    "cell_text = np.array([row1])\n",
    "\n",
    "row_labels = ['n =']\n",
    "summary_table = axis.table(cellText= cell_text,\n",
    "                           cellLoc='center',\n",
    "                           rowLabels=row_labels,\n",
    "                           rowLoc='center',\n",
    "                           colLoc='center'\n",
    "                          )\n",
    "\n",
    "summary_table.auto_set_font_size(False)\n",
    "summary_table.set_fontsize(11)\n",
    "\n",
    "properties = summary_table.properties()\n",
    "table_cells = properties['children']\n",
    "for cell in table_cells:\n",
    "    cell.set_height(0.12)\n",
    "    cell.set_alpha(0)\n",
    "\n",
    "# Saving parameters.\n",
    "filename = 'nbouts_aggression_normalized'\n",
    "plt.savefig( os.path.join(savepath, filename))\n",
    "\n",
    "plt.show()\n",
    "plt.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Bout Timing Distribution During Copulation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'virgin_virgin': [74.68,\n",
       "  1.57,\n",
       "  13.16,\n",
       "  13.56,\n",
       "  19.98,\n",
       "  21.02,\n",
       "  30.72,\n",
       "  46.3,\n",
       "  79.9,\n",
       "  82.07,\n",
       "  82.39,\n",
       "  30.31,\n",
       "  31.74,\n",
       "  42.6,\n",
       "  87.31,\n",
       "  87.88,\n",
       "  88.54,\n",
       "  7.2,\n",
       "  8.73,\n",
       "  19.29,\n",
       "  19.78,\n",
       "  23.69,\n",
       "  24.18,\n",
       "  24.46,\n",
       "  25.02,\n",
       "  28.58,\n",
       "  28.86,\n",
       "  29.14,\n",
       "  68.97,\n",
       "  98.74,\n",
       "  26.15,\n",
       "  27.3,\n",
       "  28.6,\n",
       "  29.37,\n",
       "  30.75,\n",
       "  31.67,\n",
       "  33.43,\n",
       "  14.23,\n",
       "  29.7,\n",
       "  29.77,\n",
       "  46.7,\n",
       "  78.41,\n",
       "  15.64,\n",
       "  16.27,\n",
       "  16.9,\n",
       "  21.39,\n",
       "  27.49,\n",
       "  29.38,\n",
       "  30.08,\n",
       "  30.22,\n",
       "  37.37,\n",
       "  80.01,\n",
       "  80.5,\n",
       "  93.75,\n",
       "  34.82,\n",
       "  35.17,\n",
       "  35.37,\n",
       "  42.95,\n",
       "  47.47,\n",
       "  15.8,\n",
       "  15.95,\n",
       "  55.53,\n",
       "  15.19,\n",
       "  15.81,\n",
       "  16.37,\n",
       "  20.61,\n",
       "  68.57,\n",
       "  96.35,\n",
       "  17.87,\n",
       "  30.89,\n",
       "  33.72,\n",
       "  14.9,\n",
       "  15.49,\n",
       "  17.09,\n",
       "  20.02,\n",
       "  20.31,\n",
       "  21.77,\n",
       "  23.89,\n",
       "  24.55,\n",
       "  28.13,\n",
       "  28.93,\n",
       "  30.17,\n",
       "  36.31,\n",
       "  37.11,\n",
       "  41.64,\n",
       "  45.07,\n",
       "  45.44,\n",
       "  64.21,\n",
       "  64.8,\n",
       "  74.59,\n",
       "  45.58,\n",
       "  51.72,\n",
       "  59.91,\n",
       "  12.3,\n",
       "  34.47,\n",
       "  34.98,\n",
       "  87.86,\n",
       "  98.01,\n",
       "  99.1,\n",
       "  15.08,\n",
       "  20.46,\n",
       "  20.59,\n",
       "  21.73,\n",
       "  44.86,\n",
       "  71.91,\n",
       "  41.85,\n",
       "  18.68,\n",
       "  93.64,\n",
       "  32.99,\n",
       "  33.51,\n",
       "  38.8,\n",
       "  39.26,\n",
       "  63.92,\n",
       "  74.38,\n",
       "  74.64,\n",
       "  86.0,\n",
       "  88.91,\n",
       "  42.85,\n",
       "  72.41,\n",
       "  73.16,\n",
       "  76.21,\n",
       "  76.82,\n",
       "  77.16,\n",
       "  81.57,\n",
       "  92.55,\n",
       "  34.75,\n",
       "  98.22,\n",
       "  71.07,\n",
       "  91.51,\n",
       "  36.97,\n",
       "  37.34,\n",
       "  28.78,\n",
       "  30.31,\n",
       "  47.96]}"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "onsets_dict = {condition: [] for condition in condition_order[:1]}\n",
    "\n",
    "for condition in condition_order[:1]:\n",
    "    for h, experiment in enumerate(experiments[condition]):\n",
    "            \n",
    "        experiment_path = experiment\n",
    "        experiment_name = os.path.basename(experiment)\n",
    "        \n",
    "        # Skip experiments where there is no copulation (since aggression only occurs during copulation).\n",
    "        annotation_video = annotations.read(experiment_path + '.csv')\n",
    "        try:\n",
    "            copulation = annotation_video[0].events[0]\n",
    "        except IndexError:\n",
    "            continue\n",
    "\n",
    "        # Get the list of aggression events. \n",
    "        cop_start = copulation.time\n",
    "        cop_duration_mins = copulation.duration / (60 * FPS)\n",
    "        aggression_events = annotation_video[1].events\n",
    "        n_events = len(aggression_events)\n",
    "        if n_events > 0:\n",
    "            aggression_data = annotation_video[1]\n",
    "            aggression_series = aggression_data.get_mask(N_FRAMES)\n",
    "            aggression_onsets = helpers.detect_events(aggression_series)[0]\n",
    "\n",
    "            aggression_onsets = [round(float((onset-cop_start)/(60*FPS)), 2) for onset in aggression_onsets]\n",
    "            aggression_onsets = [round(float(onset/cop_duration_mins*100), 2) for onset in aggression_onsets]\n",
    "            \n",
    "            [onsets_dict[condition].append(bout) for bout in aggression_onsets]\n",
    "\n",
    "onsets_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZsAAAEXCAYAAAB76ulbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO3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OHDh0tWVpZh21mzZkmrVq3E1dVV/vGPf4iLi0uVz2wKCwvlmWeeEUdHR2nVqpWMGjVKnnrqKXn11VdFRCQlJUWaNWsmgwYNqnLJdHx8vHTu3FmaNm0qPXv2lB07dohI9ZdW9+jRQ1auXFnjPNzPZzYuLi6Gx2pb/vLLL8XX11ccHBykS5cukpiYWO24+/btE3d39yrrz549KwEBAZUu4Jg6dao4OTnJ4MGDJTc317A+Li5OBgwYUOPvRuYBQPz8/KRbt26GnxEjRohI+evD2tpaDh48KCIiCxYskL59+4qIyIgRI+TNN98UEZH09HRp2rTpPV+rJq3ZLKPch9zcXFm/fr1ER0dLx44dpWPHjnLjxo1KoZGXlydfffWV6PV6GT16tCFgUlNTxdvbu9L+GDaWxVz3wFi6zp07y65dux54+5EjR8pnn31mworoQdzr/S01NVXatWtnWP7f//4nfn5+IiLi4OAgp06dMjz25JNPmi1sND+NtnPnTsyfPx+Ojo4ICwvDvHnzcOzYMeh0ukqfuxQUFCAwMBAHDhxA9+7dMX/+fNja2hruEXBwcNDqVyCqN95++23ExsY+0LaXLl3C0aNH8eKLL5q4KjK1mvqW3d3D7M5ea6ppHjYtW7bEe++9h++//96w7vLly7h58ya6du0Ka2trlJSUID09Hbm5uXjvvffw5JNPYtu2bbh165bhA8u7VWxHRL957rnncOPGDfz000+/e9u//OUviI2NNVywQfXP448/jmXLlgEov5LRnO2HNL8arWPHjkhKSsKf//xnXLx4EY0bN4aTkxNWrlwJHx8fjBo1Cv369cOaNWsQFhaGTp06wc7ODl27doWvry9OnTpVbWO4iu0q7q6m+s1cl2c2BOvXr3+g7e68BJq0N2DAgCpXBX7wwQewt7evcZvY2FhERkaic+fO8PT0REBAgOoyDXQid7X6JCIiMjHNT6MREZHlY9gQEZFyDBsiIlKOYUNERMoxbIiISDmGDRERKcewISIi5Rg2RESk3P8DjJayx38Qj6cAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Set bin edges based on desired bin size.\n",
    "percentage = 5\n",
    "nbins = int(100 / percentage) + 1\n",
    "bins = np.linspace(0, 100, num=nbins)\n",
    "\n",
    "# Plot histogram for each condition.\n",
    "for condition in condition_order[:1]:\n",
    "\n",
    "    # Initialize figure.\n",
    "    figure, axis = plt.subplots()\n",
    "    \n",
    "    # Change the bin weights, so that the sum of all bars is equal to 1 (otherwise the area under the kde curve is equal to 1, which is less interpretable).\n",
    "    bin_weights = np.ones_like(onsets_dict[condition]) / len(onsets_dict[condition])\n",
    "    sns.distplot(onsets_dict[condition],\n",
    "                 bins=bins,\n",
    "                 kde=False,\n",
    "                 color='steelblue',\n",
    "                 hist_kws={'alpha': 1, 'edgecolor': INK, 'weights': bin_weights}\n",
    "                )\n",
    "    \n",
    "    # Figure and axes formatting.\n",
    "    axis.set_xlabel('Copulation Time (%)', labelpad=-15)\n",
    "    axis.set_xlim(0, 101)\n",
    "    xticklabels = [int(label) for label in axis.get_xticks()]\n",
    "    xticklabels[0] = '0\\nCopulation\\nStart'\n",
    "    xticklabels[5] = '100\\nCopulation\\nEnd'\n",
    "    axis.set_xticklabels(xticklabels)\n",
    "    axis.tick_params(axis='x', length=5)\n",
    "    axis.set_ylabel('% Bouts')\n",
    "    axis.set_ylim(0, 0.14)\n",
    "    axis.set_yticks(np.arange(0, 0.14+0.01, 0.02))\n",
    "    axis.set_yticklabels([int(label*100) for label in axis.get_yticks()])\n",
    "    \n",
    "    # Saving paraemetrs.\n",
    "    filename = 'aggression_bout_timing_distribution_during_copulation_' + condition\n",
    "    plt.savefig(os.path.join(savepath, filename))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
